#pragma once

#include "Widgets/Widget.h"
#include "CollapsibleWidget.m.h"

class RVerticalPositionerWidget;

//a collapsible widget
//have a title and a content
//when click on title , content will be expanded or collapsed
//default title and content will paint nothing
RCLASS()
class WHENGINE_API RCollapsibleWidget : public RWidget
{
    ROBJECT
public:

    RCollapsibleWidget();

    RWidgetPtr GetTitle();

    TSharedObjectPtr<RVerticalPositionerWidget> GetContent();

    bool IsCollapsed() const
    {
        return bIsCollapsed;
    }

    void Expand();

    void Collapse();

    TDelegate<void> OnExpand;

    TDelegate<void> OnCollapse;

protected:
    bool bIsCollapsed=true;

    TWeakObjectPtr<RWidget> Title;
    TWeakObjectPtr<RVerticalPositionerWidget>  Content;

    virtual float CalculateContentHeight() override;
    virtual void CalculateChildrenPresentPositionAndSize() override;
    virtual void PaintSubWidgets(uint16_t&  InZOrder) override;

    float TotalHeight=0.0f;
    void ArrangeContent();
};